<template>
	<view class="homeLayout pageBg">
		
		<custom-nav-bar title="推荐"></custom-nav-bar>
		
		<view class="banner">
			<swiper :indicator-dots="true" :autoplay="true" 
			:interval="3000" :duration="500" indicator-color="rgba(255, 255, 255, 0.5)"
			indicator-active-color="#fff" circular>
				<swiper-item v-for="i in bannnerList" :key="i._id">
					
					<navigator v-if="i.target == 'miniProgram'"
					:url="i.url"
					target="miniProgram"
					:app-id="i.appid"
					class="like">
						<image :src="i.picurl" mode="aspectFill"></image>
					</navigator>
					
					<navigator v-else
					:url="`/pages/classList/classList?${i.url}`" class="like">
						<image :src="i.picurl" mode="aspectFill"></image>
					</navigator>
				</swiper-item>
				
			</swiper>
		</view>
		
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="16"></uni-icons>
				<text class="text">公告</text>
			</view>
			<view class="center">
				<swiper autoplay="true" circular
				interval="1500" duration="300" vertical>
					<swiper-item v-for="i in noticeList" :key="i._id">
						<navigator :url="'/pages/notice/detail?id='+i._id">
						{{ i.title }}
						</navigator>
					</swiper-item>
				</swiper>
			</view>
			<view class="rigth">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>
		</view>
		
		<view class="select">
			<common-title>
				<template #name>
					每日推荐
				</template>
				<template #custom>
					<view class="date">
						<view class="text">
							<uni-icons type="calendar" size="18"></uni-icons>
							<!-- <text>{{day}}号</text> -->
							<uni-dateformat :date="Date.now()" format="dd"></uni-dateformat>号
						</view>
					</view>
				</template>
			</common-title>
			
			<!-- //推荐模块 -->
			<view class="content">
				<scroll-view scroll-x="true" show-scrollbar>
					<view class="box" v-for="i in wallList" :key="i._id"
					@click="goPreview(i._id)">					
						<image :src="i.smallPicurl" 
						mode="aspectFill"></image>
					</view>	
				</scroll-view>
			</view>
			
			<!-- //专题精选 -->
			<view class="theme">
				<common-title>
					<template #name>专题精选</template>
					<template #custom>
						<navigator url="/pages/classify/classify" open-type="reLaunch" class="more">More+</navigator>
					</template>
				</common-title>
				
				<view class="content">
					<theme-item v-for="item in classfiyList"
					:key="item._id"
					:item="item"></theme-item>
					<theme-item :isMore="true"></theme-item>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import {apiGetBanner, apiGetRandomWall, apiGetNotice, apiGetClassify} from '@/Api/api.js'
import { onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app"

const bannnerList = ref([])
const wallList = ref([])		//随机的壁纸（每日推荐）
const noticeList = ref([])
const classfiyList = ref([])

//获取banner信息
const getBanner = async ()=>{
	let res =await apiGetBanner();
	console.log(res);
	bannnerList.value = res.data
}
getBanner()

//随机壁纸
const getRandomWall = async()=>{
	let res = await apiGetRandomWall();
	// console.log(res);
	wallList.value = res.data
}
getRandomWall()

// 获取公告
const getNotice = async()=>{
	let res = await apiGetNotice({select:true});
	// console.log(res.data);
	noticeList.value = res.data
}
getNotice()

//获取精选图片
const getClassify = async()=>{
	let res = await apiGetClassify({select:true});
	// console.log(res);
	classfiyList.value = res.data
}
getClassify()
	
	
//跳转预览
function goPreview (id){
	uni.setStorageSync("storgClassList",wallList.value)
	uni.navigateTo({
		url:"/pages/preview/preview?id="+id
	})
}

//分享模块
onShareAppMessage((e)=>{
	return {
		title:"壁纸推荐—su",
		path:"/pages/index/index",
		// imageUrl:'/static/xxmLogo.png'
	}
})

//分享朋友圈
onShareTimeline((e) =>{
	return {
		title:"壁纸推荐~su",
		path:"/pages/index/index",
		imageUrl:'/static/xxmLogo.png'
	}
})


</script>

<style lang="scss" scoped>
	.homeLayout{
		.banner{
			width: 750rpx;
			padding:30rpx 0;
			swiper{
				width: 750rpx;
				height: 340rpx;
				swiper-item{
					width: 100%;
					height: 100%;
					padding: 0 30rpx;
					.like{
						width: 100%;
						height: 100%;
						image{
						width: 100%;
						height: 100%;
						border-radius: 20rpx;
						}
					}
					
				}
			}
		}
		
		.notice{
			width: 690rpx;
			height: 80rpx;
			background: #f9f9f9;
			margin: 0 auto;
			border-radius: 80rpx;
			display: flex;
			// justify-content: center;
			line-height: 80rpx;
			// color: #65c7ab;
			.left{
				height: 100%;
				width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;
					:deep(){
						.uni-icons{
							color: $brand-theme-color !important;
						}
					}
				
				text{
					margin-left: 5rpx;
					color: $brand-theme-color;
					font-size: 30rpx;
					font-weight: 800;
				}
			}
			.center{
				flex: 1;
				padding: 0 30rpx;
				swiper{
					height: 100%;
					swiper-item{
						height: 100%;
						color: #666;
						font-size: 34rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}
			.rigth{
				width: 70rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
			
		.select{
			padding-top: 50rpx;
			.date{
				color: $brand-theme-color;
				:deep(){
					.uni-icons{
						color: $brand-theme-color !important;
					}
				}
			}
			.content{
				width: 720rpx;
				padding-top: 20rpx;
				margin-left: 30rpx;
				scroll-view{
					white-space: nowrap;
					.box{
						display: inline-block;
						width: 200rpx;
						height: 430rpx;
						margin-right: 15rpx;
						image{
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}
					.box:last-child{
						margin-right: 30rpx;
					}
				}
			}
		}
		
		.theme{
			padding: 50rpx 0;
			.more{
				font-size: 32rpx;
				color: #888;
			}
			.content{
				margin-top: 30rpx;
				padding: 0 30rpx;
				padding-left: 0;
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3,1fr);
			}
		}
	}
	
</style>